# Maintainer: Christoph Reiter <reiter.christoph@gmail.com>

_realname=pycairo
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python2-cairo" "${MINGW_PACKAGE_PREFIX}-python-cairo")
pkgver=1.18.2
pkgrel=2
pkgdesc="Python bindings for the cairo graphics library (mingw-w64)"
url="https://pycairo.readthedocs.io"
arch=('any')
license=('LGPL' 'MPL')
depends=("${MINGW_PACKAGE_PREFIX}-cairo")
makedepends=("${MINGW_PACKAGE_PREFIX}-python2"
             "${MINGW_PACKAGE_PREFIX}-python")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-pytest"
              "${MINGW_PACKAGE_PREFIX}-python2-pytest")
source=(https://github.com/pygobject/${_realname}/releases/download/v${pkgver}/${_realname}-${pkgver}.tar.gz)
sha256sums=('dcb853fd020729516e8828ad364084e752327d4cff8505d20b13504b32b16531')

prepare() {
  cd "${srcdir}"
  rm -rf python2-build python3-build
  cp -r ${_realname}-${pkgver} python2-build
  cp -r ${_realname}-${pkgver} python-build
}

build() {
  cd "${srcdir}"
  for builddir in python{,2}-build; do
    pushd ${builddir}
    ${MINGW_PREFIX}/bin/${builddir%-build} setup.py build
    popd
  done
}

check() {
  cd "${srcdir}"
  for builddir in python{,2}-build; do
    pushd ${builddir}
    ${MINGW_PREFIX}/bin/${builddir%-build} setup.py test
    popd
  done
}

package_python2-cairo() {
  depends+=("${MINGW_PACKAGE_PREFIX}-python2")
  cd "${srcdir}/python2-build"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
    ${MINGW_PREFIX}/bin/python2 setup.py install --prefix=${MINGW_PREFIX} --root="${pkgdir}" -O1

  install -Dm644 COPYING* -t "${pkgdir}${MINGW_PREFIX}/share/licenses/python2-cairo"
}

package_python-cairo() {
  depends+=("${MINGW_PACKAGE_PREFIX}-python")
  provides=("${MINGW_PACKAGE_PREFIX}-python3-cairo")
  conflicts=("${MINGW_PACKAGE_PREFIX}-python3-cairo")
  replaces=("${MINGW_PACKAGE_PREFIX}-python3-cairo")

  cd "${srcdir}/python-build"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
    ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} --root="${pkgdir}" -O1

  install -Dm644 COPYING* -t "${pkgdir}${MINGW_PREFIX}/share/licenses/python-cairo"
}

package_mingw-w64-i686-python2-cairo() {
  package_python2-cairo
}

package_mingw-w64-i686-python-cairo() {
  package_python-cairo
}

package_mingw-w64-x86_64-python2-cairo() {
  package_python2-cairo
}

package_mingw-w64-x86_64-python-cairo() {
  package_python-cairo
}
